<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ajax文件上传</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
</head>
<body>
<div id="result"></div>
<input type="file" id="file"/>
<button value="上传" onclick="fileUpload()"/>
<script>
    function fileUpload() {
        var file = $("#file").files[0];
        var formData = new FormData();
        formData.append("file", file);
        $.ajax({
            type: "post",
            url: "/upload",
            processData: false,
            contentType: false,
            data: formData,
            success: function (msg) {
                $("#result").html(msg);
            }
        });
    }
</script>
</body>
</html>